
// 1.准备创建开发服务器
const webpack = require('webpack')
const config = require('./webpack.config')
const Server = require('./webpack-dev-server/lib/Server');

/**
 * 
 * @param {*} compiler webpack编译对象
 * @param {*} options webpack的配置项
 */
function startDevServer(compiler,options) {
    //获取devServer配置项
    const devServerArgs = options.devServer||{}; 
    // 3.启动HTTP服务器，里面还会负责打包我们的项目并提供预览服务，通过它访问打包后的文件
    const server = new Server(compiler, devServerArgs);
    const {host='localhost',port=9000}=devServerArgs;
    server.listen(port, host, (err) => {
        console.log(`Project is running at http://${host}:${port}`);
    });
}
// 2.创建webpack实例
const compiler = webpack(config);
debugger
// 3.启动HTTP服务器
startDevServer(compiler,config);

module.exports = startDevServer